package databaseAcces;
import java.sql.*;
import javax.swing.*;

/**
*This class handle the connectn of mysql database
* @version  1.0
* @author <a href="">Cheikh Mbacke Thiam</a>
*/
public class Connexion {

private Connection conect;

/**
 * Construct that create connection
 */
public Connexion () {
conect =  initConnection();
}


/**
 * return the link to connection
 */
public Connection getConnexion() {
	return conect;
}


/**
 *Allow the initialization of connection
 * @return return Connection
 * @exception SQLException
 * @exception ClassNotFoundException
 */
public Connection initConnection() {

	Connection co = null;
	String url = "jdbc:mysql://localhost/fejob";  
	try {
		Class.forName("org.gjt.mm.mysql.Driver");
		co = DriverManager.getConnection(url,"root","");
	}
	catch (ClassNotFoundException e) {
		JOptionPane.showMessageDialog(null,"Driver introuvable :"+e.getMessage());
	}
	catch (SQLException fe) {
		JOptionPane.showMessageDialog(null,"Connection impossible :"+fe.getMessage());
	}
	return co;
}



/**
 * Allow to close the connection
 *
 * @exception SQLException
 */

public void closeConnexion() {
	try {

	conect.close();
    }
    catch (SQLException ef) {
		JOptionPane.showMessageDialog(null,"Probleme de fermeture"+ef.getMessage());
	}
}

}